package com.btex.app.treaty.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.btex.app.Config;
import com.btex.app.R;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author zy zhangyi <zhangyi, 1104745049@QQ.com
 * @version v1.0
 * @project study1
 * @Description
 * @encoding UTF-8
 * @date 2018/10/15
 * @time 下午6:05
 * @修改记录 <pre>
 * 版本       修改人         修改时间         修改内容描述
 * --------------------------------------------------
 * <p>
 * --------------------------------------------------
 * </pre>
 */

public class CheckPriceDialog extends Dialog {


    @BindView(R.id.treaty_dialog_tv_check_xianjia)
    TextView mTreatyDialogTvCheckXianjia;
    @BindView(R.id.treaty_dialog_tv_check_market)
    TextView mTreatyDialogTvCheckMarket;
    @BindView(R.id.treaty_dialog_tv_check_diss)
    TextView mTreatyDialogTvCheckDiss;
    private Context mContext;

    public CheckPriceDialog(@NonNull Context context) {
        super(context, R.style.coupon_style);
        mContext = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.check_price_dialog);
        ButterKnife.bind(this);


        //获取屏幕宽高
        DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
        //屏幕宽
        int widthPixels = displayMetrics.widthPixels;
        //屏幕高
        int heightPixels = displayMetrics.heightPixels;
        WindowManager.LayoutParams attributes = getWindow().getAttributes();
        //设置给attributes
        attributes.width = (int) (widthPixels * 1);
        attributes.height = (int) (heightPixels * 0.3);
        //让Dialog位置居中
        attributes.gravity = Gravity.BOTTOM;
        getWindow().setAttributes(attributes);
        //点击空白处不dismiss
        setCanceledOnTouchOutside(true);

    }

    @OnClick({R.id.treaty_dialog_tv_check_xianjia, R.id.treaty_dialog_tv_check_market, R.id.treaty_dialog_tv_check_diss})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.treaty_dialog_tv_check_xianjia:

                Config.ISLIMIT = mContext.getString(R.string.heyue_xianjia_shijia);
                EventBus.getDefault().post("Refreshs");
                dismiss();

                break;
            case R.id.treaty_dialog_tv_check_market:
                Config.ISLIMIT = mContext.getString(R.string.heyue_shjia);
                EventBus.getDefault().post("Refreshs");
                dismiss();
                break;
            case R.id.treaty_dialog_tv_check_diss:
                dismiss();
                break;
        }
    }
}
